<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column prop="orderBy" label="排序" width="60">
      </el-table-column>
      <el-table-column prop="name" label="名称" width="180"> </el-table-column>
      <el-table-column prop="fileId" label="缩略图">
        <template slot-scope="scope">
          <img
            class="thumb"
            :src="scope.row.file.httpUrl"
            :alt="scope.row.bannerName"
            @click="handleLook(scope.row)"
            title="点击预览"
          />
        </template>
      </el-table-column>
      <el-table-column prop="isShow" label="是否显示">
        <template slot-scope="scope">
          <span v-show="scope.row.isShow == 0">显示</span>
          <span v-show="scope.row.isShow == 1">隐藏</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间"> </el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              :disabled="$button('752') == false ? true : false"
              @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button
              type="danger"
              size="mini"
              :disabled="$button('753') == false ? true : false"
              @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
    <ImgPreview />
  </div>
</template>
<script>
import {
  sysBannerQuery,
  sysBannerDelete,
} from '@/api/admin/system/sysBanner.js'
import Bus from '@/utils/bus.js'
export default {
  components: {
    ImgPreview: () => import('@/components/resource/imgPreview.vue'),
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
      },
      tableData: [],
      pageObj: {},
    }
  },
  mounted() {
    this.getList()
    Bus.$on('refreshBannerList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshBannerList')
  },
  methods: {
    getList() {
      sysBannerQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.pageObj = res.data
      })
    },
    //预览
    handleLook(row) {
      Bus.$emit('showDialogimgPreview', row.file)
    },
    //编辑
    handleEdit(row) {
      Bus.$emit('showDialogBannerAdd', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      sysBannerDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped>
.thumb {
  width: auto;
  height: 30px;
  cursor: pointer;
}
</style>